package me.militch.quickcore.core;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.List;

import me.militch.quickcore.di.component.AppComponent;
import me.militch.quickcore.di.module.ActivityModule;

public class DaggerActivityCallback<T> implements Application.ActivityLifecycleCallbacks {
    private AppComponent appComponent;
    private HasDaggerApplication<T> hasDaggerApplication;
    private T call;
    public DaggerActivityCallback(HasDaggerApplication<T> hasDaggerApplication,AppComponent appComponent){
        this.hasDaggerApplication = hasDaggerApplication;
        this.appComponent = appComponent;
    }
    @Override
    @SuppressWarnings("unchecked")
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        Log.e(getClass().getSimpleName(),"-onActivityCreated");
        if(activity instanceof HasDaggerInject){
            HasDaggerInject<T> callActivity = (HasDaggerInject<T>) activity;
            call = hasDaggerApplication.activityComponent(appComponent,new ActivityModule(activity));
            callActivity.inject(call);
        }
    }


    @Override
    public void onActivityStarted(Activity activity) {
        Log.e(getClass().getSimpleName(),"-onActivityStarted");


    }

    @Override
    public void onActivityResumed(Activity activity) {
        DaggerFragmentCallback<T> daggerFragmentCallback = new DaggerFragmentCallback<>(activity,call);
        daggerFragmentCallback.callInject();
    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }
}
